<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <hta:application
      id="NetSettingTool"
      version="2.0.0"
    />
    <title>网络设置工具 v2.0</title>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <link href="lib/css/bootstrap.min.css?v=3.3.7" rel="stylesheet" />
    <link href="lib/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" />
    <link href="lib/css/toastr/toastr.min.css" rel="stylesheet">
    <link href="lib/css/animate.css" rel="stylesheet" />
    <link href="lib/css/style.css?v=4.1.0" rel="stylesheet" />

    <script src="lib/js/jquery.min.js?v=2.1.4"></script>
    <script src="lib/js/bootstrap.min.js?v=3.3.7"></script>
    <script src="lib/js/ini-config.js"></script>
    <script src="lib/js/toastr/toastr.min.js"></script>
    <script src="lib/plugin/layer/layer.js"></script>

    <script>
      //================================
      // 全局变量
      //================================
      // Shell.Application 对象 (推荐使用)
      var shell = new ActiveXObject("Shell.Application");
      // WScript.Shell 对象
      var wsh = new ActiveXObject("Wscript.Shell");
      // Scripting.FileSystemObject 对象
      var fso = new ActiveXObject("Scripting.FileSystemObject");
      // Scripting.Dictionary 对象
      var dict = new ActiveXObject("Scripting.Dictionary");

      //================================
      // 初始配置 (无需修改)
      //================================
      // 多环境
      var profileItems = "开发;测试;生产"
      // 默认环境
      var profileName = "开发"
      // 以太网名称
      var netName = "以太网"
      // IP地址
      var ipAddr = "10.185.224.37"
      // 子网掩码
      var ipMask = "255.255.255.0"
      // 网关
      var ipGateway = "10.185.224.1"
      // 首选DNS
      var ipDns1 = "10.33.176.66"
      // 备用DNS
      var ipDns2 = "10.33.176.67"
      // 代理服务器
      var proxyServer = "http://proxy1.bj.petrochina:8080"
      // 代理服务器
      var proxyOverride = "10.*;11.*;*.cnpc;*.cnpc.*;*.petrochina;*.petrochina.*;dj.*"
      // 无线网名称
      var wifiName = "WLAN"
      // 默认wifi名
      var defaultSsid = "TP-LINK_YLL"

      // 配置文件路径
      var configFilePath = "conf\\config.txt";
      // 多环境基础路径
      var profileBasePath = "conf\\config-{{profile}}.txt";
      // wifi ssid 文件路径
      var wifiFilePath = "conf\\wifi.txt"
      // wifi 密码文件路径
      var wifiPassFile = "conf\\wifiPass.txt"
      
      //================================
      // 常量定义
      //================================
      // 读写模式 - 只读
      var IO_FOR_READING = 1;
      // 读写模式 - 写入
      var IO_FOR_WRITING = 2;
      // 读写模式 - 追加
      var IO_FOR_APPENDING = 3;
      // 创建标识 - true
      var CREATE_FLAG_TRUE = true;
      // 创建标识 - false
      var CREATE_FLAG_FALSE = false;
      // 窗口风格 - 隐藏
      var WINDOW_STYLE_HIDE = 0;
      // 窗口风格 - 显示 (默认)
      var WINDOW_STYLE_SHOW = 1;
      // 窗口风格 - 最小化
      var WINDOW_STYLE_MIN = 2;
      // 窗口风格 - 最大化
      var WINDOW_STYLE_MIN = 3;
      // 等待返回标识 - true
      var WAIT_FLAG_TRUE = true;
      // 等待返回标识 - false
      var WAIT_FLAG_FALSE = true;
      // 显示标识 - 显示 - 1
      var SHOW_FLAG_1 = 1;
      // 显示标识 - 隐藏 - 0
      var SHOW_FLAG_0 = 0;

      // 初始化数据
      $(function(){
        // 多环境
        $("#profileItems").val(profileItems);
        // 默认环境
        $("#profileName").val(profileName);
        // 以太网名称
        $("#netName").val(netName);
        // IP地址
        $("#ipAddr").val(ipAddr);
        // 子网掩码
        $("#ipMask").val(ipMask);
        // 网关
        $("#ipGateway").val(ipGateway);
        // 首选DNS
        $("#ipDns1").val(ipDns1);
        // 备用DNS
        $("#ipDns2").val(ipDns2);
        // 代理服务器
        $("#proxyServer").val(proxyServer);
        // 禁用代理
        $("#proxyOverride").val(proxyOverride);
        // 无线网名称
        $("#wifiName").val(wifiName);
        // 默认wifi名
        $("#defaultSsid").val(defaultSsid);
        // 读取配置
        if (fso.FileExists(configFilePath)) {
          readProfileConfig();
        }
        // 读取配置
        if (fso.FileExists(getProfileFilePath())) {
          readConfig();
        }

        // 初始化多环境列表
        initProfileItemList();
        $("#profileItemList").change(function() {
           $("#profileName").val($(this).val());
           readConfig();
        });

        // 窗口大小
        winWidth = 1280;
        winHeight = 800;
        resizeTo(winWidth, winHeight);
        // 窗口位置
        winLeft = (screen.width - winWidth) / 2;
        winTop = (screen.height - winHeight) / 2;
        moveTo(winLeft, winTop);
      }); 
      
      // toastr 弹窗
      toastr.options = {
        "closeButton": true,
        "progressBar": true,
        "positionClass": "toast-top-center",
      };

    </script>

  </head>

  <body class="gray-bg">

    <div class="wrapper wrapper-content animated fadeInRight">

      <div class="row">

        <!-- 操作区 -->
        <div class="col-xs-5">

          <!-- 常用操作 -->
          <div class="row">
            <div class="panel panel-success">
              <div class="panel-heading">
                <i class="fa fa-tags"></i>&nbsp;常用操作
              </div>
              <div class="panel-body">
                  <form class="form-horizontal">
                    <div class="form-group">
                      <label class="col-xs-2 control-label">以太网：</label>
                      <div class="col-xs-10">
                        <button class="btn btn-sm btn-primary" type="button" onclick="openNet()"><i class="fa fa-play"></i>&nbsp;开启</button>
                        <button class="btn btn-sm btn-danger" type="button" onclick="closeNet()"><i class="fa fa-stop"></i>&nbsp;关闭</button>
                        <button class="btn btn-sm btn-success" type="button" onclick="setNet()"><i class="fa fa-cog"></i>&nbsp;设置</button>
                        <button class="btn btn-sm btn-warning" type="button" onclick="resetNet()"><i class="fa fa-undo"></i>&nbsp;重置</button>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-xs-2 control-label">代理：</label>
                      <div class="col-xs-10">
                        <button class="btn btn-sm btn-primary" type="button" onclick="openProxy()"><i class="fa fa-play"></i>&nbsp;开启</button>
                        <button class="btn btn-sm btn-danger" type="button" onclick="colseProxy()"><i class="fa fa-stop"></i>&nbsp;关闭</button>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-xs-2 control-label">无线网：</label>
                      <div class="col-xs-10">
                        <button class="btn btn-sm btn-primary" type="button" onclick="openWifi()"><i class="fa fa-play"></i>&nbsp;开启</button>
                        <button class="btn btn-sm btn-danger" type="button" onclick="closeWifi()"><i class="fa fa-stop"></i>&nbsp;关闭</button>
                        <button class="btn btn-sm btn-primary" type="button" onclick="connectWifi()"><i class="fa fa-link"></i>&nbsp;连接</button>
                        <button class="btn btn-sm btn-warning" type="button" onclick="disconnectWifi()"><i class="fa fa-unlink"></i>&nbsp;断开</button>
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="col-xs-2 control-label">防火墙：</label>
                      <div class="col-xs-10">
                        <button class="btn btn-sm btn-primary" type="button" onclick="openWall()"><i class="fa fa-play"></i>&nbsp;开启</button>
                        <button class="btn btn-sm btn-danger" type="button" onclick="closeWall()"><i class="fa fa-stop"></i>&nbsp;关闭</button>
                      </div>
                    </div>
                  </form>
              </div>
            </div>
          </div>

          <!-- 全局按钮 -->
          <div class="row">
            <div class="panel panel-primary">
              <div class="panel-heading">
                <i class="fa fa-anchor"></i>&nbsp;全局按钮
              </div>
              <div class="panel-body">
                  <form class="form-horizontal">

                    <div class="form-group">
                        <div class="col-xs-12">
                          <button class="btn btn-sm btn-primary" type="button" onclick="ncpa()"><i class="fa fa-wifi"></i>&nbsp;适配器</button>
                          <button class="btn btn-sm btn-warning" type="button" onclick="uacSetting()"><i class="fa fa-user"></i>&nbsp;账户控制</button>
                          <button class="btn btn-sm btn-success" type="button" onclick="openHostDir()"><i class="fa fa-file-o"></i>&nbsp;host目录</button>
                        </div>
                    </div>
                  </form>
              </div>
            </div>
          </div>

          <!-- 说明 -->
          <div class="row">
            <div class="panel panel-info">
              <div class="panel-body">
                <div class="tabs-container">
                  <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tabMulti" aria-expanded="true">多环境</a></li>
                    <li class=""><a data-toggle="tab" href="#tabNet" aria-expanded="false">以太网 / 有线网名称</a></li>
                    <li class=""><a data-toggle="tab" href="#tabWifi" aria-expanded="false">无线网</a></li>
                    <li class=""><a data-toggle="tab" href="#tab3Q" aria-expanded="false">鸣谢</a></li>
                  </ul>
                  <div class="tab-content">
                    <!-- 多环境 -->
                    <div id="tabMulti" class="tab-pane active">
                      <div class="panel-body">
                        <p>多环境操作步骤：<br>
                          <span style="color:red; font-weight: bold;">0、支持新增和删除操作</span><br>
                          1、下拉选择环境，即可切换至对应环境配置<br>
                          2、修改当前环境下的以太网，代理，无线网配置<br>
                          3、点击保存配置，即可保存配置<br>
                          4、最后一次保存的就是下次打开的默认配置。<br>
                        </p>
                      </div>
                    </div>
    
                    <!-- 网络名称 -->
                    <div id="tabNet" class="tab-pane">
                      <div class="panel-body">
                        <p><span style="color:red; font-weight: bold;">以太网 / 无线网名称</span> 的修改：<br>
                          1、点击 <button class="btn btn-sm btn-primary" type="button" onclick="ncpa()"><i class="fa fa-wifi"></i>&nbsp;适配器</button>，打开网络适配器界面<br>
                          2、找到以太网或无线网的适配器，右键 -> 重命名，复制适配器名称。<br>
                          3、修改右侧配置<span style="color:red; font-weight: bold;">以太网 / 无线网名称</span>和适配器保持一致即可。<br>
                          4、<span style="color:red; font-weight: bold;">注意</span>：以太网名称和无线网名称，必须和自己电脑的保持一致。
                        </p>
                      </div>
                    </div>
    
                    <!-- 无线网 -->
                    <div id="tabWifi" class="tab-pane">
                      <div class="panel-body">
                        <p>
                          1、连接默认wifi 功能，需要设置默认wifi名<br>
                          2、查看wifi密码功能，需要先获取已连接wifi，再查看wifi 密码<br>
                          3、<span style="color:red; font-weight: bold;">注意</span>：开启wifi才能正常使用。
                        </p>
                      </div>
                    </div>
    
                    <!-- 鸣谢 -->
                    <div id="tab3Q" class="tab-pane">
                        <div class="panel-body">
                          <p>
                            1、感谢<span style="color:red; font-weight: bold;">索浩然，孙源，吴子达</span>的支持<br>
                            2、本工具基于索浩然同学的命令行版改造而来<br>
                            3、由孙源同学和吴子达同学测试使用，提供改善思路<br>
                          </p>
                        </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>


          </div>
        </div>

        <!-- 配置区 -->
        <div class="col-xs-7">
          <!-- 设置多环境 -->
          <div class="row">
            <div class="col-xs-12">
              <div class="panel panel-success">
                  <div class="panel-heading">
                    <i class="fa fa-sitemap"></i>&nbsp;多环境
                  </div>
                  <div class="panel-body">
                    <form class="form-horizontal">

                      <div class="form-group">
                        <label class="col-xs-2 control-label">切换环境：</label>
                        <div class="col-xs-10">
                          <div class="row">
                            <div class="col-md-6">
                              <input id="profileName" type="hidden">
                              <input id="profileItems" type="hidden">
                              <select id="profileItemList" class="form-control"></select>
                            </div>
                            <div class="col-md-6">
                              <button class="btn btn-sm btn-primary" type="button" onclick="addConfig()"><i class="fa fa-plus"></i>&nbsp;新增</button>
                              <button class="btn btn-sm btn-danger" type="button" onclick="deleteConfig()"><i class="fa fa-remove"></i>&nbsp;删除</button>
                              <button class="btn btn-sm btn-success" type="button" onclick="saveConfig()"><i class="fa fa-save"></i>&nbsp;保存</button>
                              <button class="btn btn-sm btn-info" type="button" style="display: none;"><i class="fa fa-heart"></i>&nbsp;默认</button>
                            </div>
                          </div>
                        </div>
                      </div>

                    </form>

                    <!-- 以太网 -->
                    <div class="ibox float-e-margins" style="margin: 0px;">
                      <div class="ibox-title">
                        <h5><i class="fa fa-tv"></i>&nbsp;以太网</h5>
                        <div class="ibox-tools">
                          <a class="collapse-link">
                              <i class="fa fa-chevron-up"></i>
                          </a>
                        </div>
                      </div>
                      <div class="ibox-content">
                        <form class="form-horizontal">
                          <div class="form-group">
                            <label class="col-xs-2 control-label">以太网名称：</label>
                            <div class="col-xs-10">
                              <div class="row">
                                <div class="col-md-6">
                                  <input id="netName" type="text" class="form-control" placeholder="以太网名称">
                                </div>
                              </div>
                            </div>
                          </div>
                          <div class="form-group">
                            <label class="col-xs-2 control-label">IP & 掩码：</label>
                            <div class="col-xs-10">
                              <div class="row">
                                  <div class="col-md-6">
                                    <input id="ipAddr" type="text" class="form-control" placeholder="IP">
                                  </div>
                                  <div class="col-md-6">
                                    <input id="ipMask" type="text" class="form-control" placeholder="子网掩码">
                                  </div>
                              </div>
                            </div>
                          </div>
                          <div class="form-group">
                            <label class="col-xs-2 control-label">网关：</label>
                            <div class="col-xs-10">
                              <div class="row">
                                  <div class="col-md-6">
                                    <input id="ipGateway" type="text" class="form-control" placeholder="网关">
                                  </div>
                              </div>
                            </div>
                          </div>
    
                          <div class="form-group">
                            <label class="col-xs-2 control-label">DNS：</label>
                            <div class="col-xs-10">
                              <div class="row">
                                  <div class="col-md-6">
                                    <input id="ipDns1" type="text" class="form-control" placeholder="首选">
                                  </div>
                                  <div class="col-md-6">
                                    <input id="ipDns2" type="text" class="form-control" placeholder="备用">
                                  </div>
                              </div>
                            </div>
                          </div>
    
                        </form>

                      </div>
                    </div>

                    <!-- 代理 -->
                    <div class="ibox float-e-margins" style="margin: 0px;">
                      <div class="ibox-title">
                        <h5><i class="fa fa-paper-plane-o"></i>&nbsp;代理</h5>
                        <div class="ibox-tools">
                          <a class="collapse-link">
                              <i class="fa fa-chevron-up"></i>
                          </a>
                        </div>
                      </div>
                      <div class="ibox-content">
                        <form class="form-horizontal">
                          <div class="form-group">
                              <label class="col-xs-2 control-label">服务器：</label>
                              <div class="col-xs-10">
                                  <input id="proxyServer" type="url" class="form-control">
                              </div>
                          </div>
                          <div class="form-group">
                              <label class="col-xs-2 control-label">排除地址：</label>
                              <div class="col-xs-10">
                                <textarea id="proxyOverride" class="form-control"></textarea>
                              </div>
                          </div>

                        </form>

                      </div>
                    </div>

                    <!-- 无线网 -->
                    <div class="ibox float-e-margins" style="margin: 0px;">
                      <div class="ibox-title">
                        <h5><i class="fa fa-wifi"></i>&nbsp;无线网</h5>
                        <div class="ibox-tools">
                          <a class="collapse-link">
                              <i class="fa fa-chevron-down"></i>
                          </a>
                        </div>
                      </div>
                      <div class="ibox-content" style="display: none;">
                        <form class="form-horizontal">
                          <div class="form-group">
                            <label class="col-xs-2 control-label">无线网名称：</label>
                            <div class="col-xs-10">
                                <input id="wifiName" type="text" class="form-control">
                            </div>
                          </div>
                          <div class="form-group">
                            <label class="col-xs-2 control-label">默认WIFI：</label>
                            <div class="col-xs-10">
                                <input id="defaultSsid" type="text" class="form-control">
                            </div>
                          </div>
                          <div class="form-group">
                            <label class="col-xs-2 control-label">WIFI名称：</label>
                            <div class="col-xs-10">
                              <select id="wifiSsid" class="form-control"></select>
                            </div>
                          </div>
    
                          <div class="form-group">
                              <div class="col-xs-offset-3 col-xs-8">
                                <button class="btn btn-sm btn-success" type="button" onclick="showWifiPassword()">查看</button>
                                <button class="btn btn-sm btn-info" type="button" onclick="getWifiList()">获取</button>
                                <button class="btn btn-sm btn-danger" type="button" onclick="deleteWifi()">删除</button>
                              </div>
                          </div>
                        </form>

                      </div>
                    </div>

                  </div>
              </div>
            </div>
          </div>

        </div>

      </div>

    </div>

  </body>

  <script>
    // 获取页面配置
    function getConf() {
      // 多环境
      profileItems = $("#profileItems").val();
      // 默认环境
      profileName = $("#profileName").val();
      // 以太网名称
      netName = $("#netName").val();
      // IP地址
      ipAddr = $("#ipAddr").val();
      // 子网掩码
      ipMask = $("#ipMask").val();
      // 网关
      ipGateway = $("#ipGateway").val();
      // 首选DNS
      ipDns1 = $("#ipDns1").val();
      // 备用DNS
      ipDns2 = $("#ipDns2").val();
      // 代理服务器
      proxyServer = $("#proxyServer").val();
      // 禁用代理地址
      proxyOverride = $("#proxyOverride").val();
      // 无线网名称
      wifiName = $("#wifiName").val();
      // 默认wifi名
      defaultSsid = $("#defaultSsid").val();
    }

    // 显示消息
    function showMsg(msg, time, isError) {
      toastr.success(msg);
    }

    // 显示错误消息
    function showErrMsg(msg) {
      toastr.error(msg); 
    }

    // 显示警告消息
    function showWarnMsg(msg) {
      toastr.warning(msg); 
    }
  </script>
  
  <script>

    // 保存多环境配置
    function saveProfileConfig() {

      // 获取页面配置
      getConf();

      // 更新到配置文件
      var configFile = fso.OpenTextFile(configFilePath, IO_FOR_WRITING, CREATE_FLAG_TRUE);
      configFile.WriteLine("profileItems=" + profileItems);
      configFile.WriteLine("profileName=" + profileName);

      configFile.Close();

    }

    // 读取多环境配置
    function readProfileConfig() {
      if (!fso.FileExists(configFilePath)) {
        showErrMsg("文件不存在");
        return;
      }

      var configFile = fso.OpenTextFile(configFilePath, IO_FOR_READING);

      do {
        var line = $.trim(configFile.ReadLine());
        if (line) {
          var configArr = line.split("=");
          $("#" + configArr[0]).val(configArr[1]);
        }
      } while (!configFile.AtEndOfLine);
      
    }

    // 获取多环境路径
    function getProfileFilePath() {
      return profileBasePath.replace("{{profile}}", $("#profileName").val());
    }

    // 添加配置
    function addConfig() {
      layer.prompt({
        title: '请输入环境',
        closeBtn: 0,
      }, function(value, index, elem){
        var profileItemStr = $("#profileItems").val();
        profileItemStr = profileItemStr + ";" + value;
        $("#profileItems").val(profileItemStr);
        $("#profileName").val(value);
        initProfileItemList();
        layer.close(index);
        saveProfileConfig();
      });
      
    }

    // 删除配置
    function deleteConfig() {
      layer.confirm('温馨提示：删除后数据无法恢复！',{
        title: '是否删除？',
        closeBtn: 0,
      }, function(){
        // 确定操作
        delConfig();
      }, function(){
        // 取消操作
      });
    }

    // 删除配置
    function delConfig() {
      var profileItemList = $("#profileItems").val().split(";");

      if (profileItemList.length <= 1) {
        layer.msg('不能全部删除！', {icon: 2});
        return;
      }

      var selectedProfile = $("#profileItemList").val();
      var profileItemListTemp = "";
      $("#profileItemList").empty();
      for(var i = 0; i < profileItemList.length; i++) {
        if (selectedProfile !== profileItemList[i]) {
          $("#profileItemList").append("<option value='" + profileItemList[i] + "'>" + profileItemList[i] + "</option>");
          profileItemListTemp += profileItemList[i] + ";";
        }
      }

      $("#profileName").val($("#profileItemList").val());
      $("#profileItems").val(profileItemListTemp.substring(0, profileItemListTemp.length - 1));
      saveProfileConfig();
      layer.msg('数据已删除！', {icon: 1});
    }

    // 读取配置
    function initProfileItemList() {
      var profileItemList = $("#profileItems").val().split(";");
      $("#profileItemList").empty();
      for(var i = 0; i < profileItemList.length; i++) {
        $("#profileItemList").append("<option value='" + profileItemList[i] + "'>" + profileItemList[i] + "</option>");
      }
      
      $("#profileItemList").val($("#profileName").val());
    }

    // 保存配置
    function saveConfig() {
      
      saveProfileConfig();

      // 更新到配置文件
      // 多环境配置
      var profileFilePath = getProfileFilePath();
      var configFile = fso.OpenTextFile(profileFilePath, IO_FOR_WRITING, CREATE_FLAG_TRUE);
      configFile.WriteLine("netName=" + netName);
      configFile.WriteLine("ipAddr=" + ipAddr);
      configFile.WriteLine("ipMask=" + ipMask);
      configFile.WriteLine("ipGateway=" + ipGateway);
      configFile.WriteLine("ipDns1=" + ipDns1);
      configFile.WriteLine("ipDns2=" + ipDns2);
      configFile.WriteLine("proxyServer=" + proxyServer);
      configFile.WriteLine("proxyOverride=" + proxyOverride);
      configFile.WriteLine("wifiName=" + wifiName);
      configFile.WriteLine("defaultSsid=" + defaultSsid);

      configFile.Close();

      showMsg("保存配置成功");
    }

    // 读取配置
    function readConfig() {
      // 多环境配置
      var profileFilePath = getProfileFilePath();
      if (!fso.FileExists(profileFilePath)) {
        saveConfig();
      }

      var configFile = fso.OpenTextFile(profileFilePath, IO_FOR_READING);

      do {
        var line = $.trim(configFile.ReadLine());
        if (line) {
          var configArr = line.split("=");
          $("#" + configArr[0]).val(configArr[1]);
        }
      } while (!configFile.AtEndOfLine);

    }

    // 打开host目录
    function openHostDir() {
      shell.ShellExecute("explorer.exe", "C:\\Windows\\System32\\drivers\\etc");
    }

    // 打开网络适配器
    function ncpa() {
      shell.ShellExecute("cmd.exe", "/c ncpa.cpl ", "", "", SHOW_FLAG_0);
    }

    // 打开用户账户控制
    function uacSetting() {
      shell.ShellExecute("UserAccountControlSettings");
    }

    // 开启以太网
    function openNet() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + netName + "\" admin=enabled", "", "runas", SHOW_FLAG_0);
      showMsg("开启以太网成功");
    }

    // 关闭以太网
    function closeNet(){
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + netName + "\" admin = disabled", "", "runas", SHOW_FLAG_0);
      showErrMsg("关闭以太网成功");
    }

    // 设置以太网
    function setNet() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + netName + "\" admin = enabled", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set address name = \"" + netName + "\" source = static address = " + ipAddr + " mask = " + ipMask + " gateway = " + ipGateway, "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set dns name = \"" + netName + "\" source = static address = " + ipDns1 + " validate = no", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip add dns name = \"" + netName + "\" address = " + ipDns2 + " validate = no", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set wins name = \"" + netName + "\" source = static address = " + ipDns1 , "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip add wins name = \"" + netName + "\" address = " + ipDns2 , "", "runas", SHOW_FLAG_0);
      showMsg("设置以太网成功");
    }

    // 重置以太网
    function resetNet() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + netName + "\" admin=enabled", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set address name = \"" + netName + "\" source = dhcp", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set dns name = \"" + netName + "\" source = dhcp", "", "runas", SHOW_FLAG_0);
      shell.ShellExecute("cmd.exe", "/c netsh interface ip set wins name = \"" + netName + "\" source = dhcp", "", "runas", SHOW_FLAG_0);

      showWarnMsg("重置以太网成功");
    }

    // 开启无线网
    function openWifi() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + wifiName + "\" enabled", "", "runas", SHOW_FLAG_0);
      showMsg("开启无线网成功");
    }

    // 关闭无线网
    function closeWifi() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh interface set interface \"" + wifiName + "\" disabled", "", "runas", SHOW_FLAG_0);
      showErrMsg("关闭无线网成功");
    }

    // 获取选择的wifi 的ssid
    function getSelectedSsid() {
      var selected = $.trim($("#wifiSsid").val());
      var defaultSsid = $.trim($("#defaultSsid").val());
      if (!selected) {
        selected = defaultSsid;
      }
      return selected;
    }

    // 连接无线网
    function connectWifi() {
      getConf()
      var selected = getSelectedSsid();
      shell.ShellExecute("cmd.exe", "/c netsh wlan connect name = \"" + selected + "\" ", "", "runas", SHOW_FLAG_0);
      showMsg("连接无线网成功");
    }

    // 断开无线网
    function disconnectWifi() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh wlan disconnect", "", "runas", SHOW_FLAG_0);
      showWarnMsg("断开无线网成功");
    }

    // 删除无线网
    function deleteWifi() {
      getConf()
      var selected = getSelectedSsid();
      shell.ShellExecute("cmd.exe", "/c netsh wlan delete profile name = \"" + selected + "\"", "", "runas", SHOW_FLAG_0);
      showMsg("删除无线网成功");
    }

    // 查看已连接Wifi信息
    function getWifiList() {

      // 输出空行
      shell.ShellExecute("cmd.exe", "/c echo= > " + wifiFilePath, "", "", SHOW_FLAG_0);
      // 输出已连接WiFi名
      shell.ShellExecute("cmd.exe", "/c for /f \"skip=9 tokens=1,2 delims=:\" %i in ('netsh wlan show profiles') do @echo %j | findstr -i -v echo >> " + wifiFilePath, "", "", SHOW_FLAG_0);

      var wifiStream = fso.OpenTextFile(wifiFilePath, IO_FOR_READING);

      var wifiList = [];
      do {
        var line = $.trim(wifiStream.ReadLine());
        if (line) {
          wifiList.push(line);
        }
      } while (!wifiStream.AtEndOfLine);

      $("#wifiSsid").empty();
      for(var i = 0; i < wifiList.length; i++) {
        $("#wifiSsid").append("<option value='" + wifiList[i] + "'>" + wifiList[i] + "</option>");
      }
      showMsg("获取Wifi列表成功");
    }

    // 查看已连接Wifi信息
    function showWifiPassword() {
      var selected = getSelectedSsid();


      wsh.Run("cmd.exe /c echo= > " + wifiPassFile, WINDOW_STYLE_HIDE, WAIT_FLAG_TRUE);
      wsh.Run("cmd.exe /c netsh wlan show profile name=\"" + selected + "\" key=clear | findstr 关键内容 >> " + wifiPassFile, WINDOW_STYLE_HIDE, WAIT_FLAG_TRUE);
      wsh.Run('cmd.exe /c for /f \"tokens=1,2 delims=:" %i in (' + wifiPassFile + ') do @echo %j | findstr -i -v echo > ' + wifiPassFile, WINDOW_STYLE_HIDE, WAIT_FLAG_TRUE);
      wsh.Run("cmd.exe /c ping -n 1 127.0.0.1 > nul", WINDOW_STYLE_HIDE, WAIT_FLAG_TRUE);

      var wifiPassStream = fso.OpenTextFile(wifiPassFile, IO_FOR_READING);
      var wifiPass = "";
      do {
        var line = $.trim(wifiPassStream.ReadLine());
        if (line) {
          wifiPass = line;
        }
      } while (!wifiPassStream.AtEndOfLine);

      // 清空密码
      wsh.Run("cmd.exe /c echo= > " + wifiPassFile, WINDOW_STYLE_HIDE, WAIT_FLAG_TRUE);

      showMsg("WIFI密码：" + wifiPass);
    }

    // 开启代理
    function openProxy() {
      getConf()
      // 代理服务器
      proxyServer = $("#proxyServer").val();
      // 禁用代理地址
      proxyOverride = $("#proxyOverride").val()
      // 基础路径 
      regBasePath = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\";
      
      // 代理启用状态
      wsh.RegWrite(regBasePath + "ProxyEnable", "00000001", "REG_DWORD");
      // 代理服务器
      wsh.RegWrite(regBasePath + "ProxyServer", proxyServer, "REG_SZ");
      // 禁用代理地址
      wsh.RegWrite(regBasePath + "ProxyOverride", proxyOverride, "REG_SZ");

      showMsg("开启代理成功")
    }


    // 关闭代理
    function colseProxy() {
      getConf()
      // 基础路径 
      regBasePath = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\";
      
      // 代理启用状态
      wsh.RegWrite(regBasePath + "ProxyEnable", "00000000", "REG_DWORD");
      // 代理服务器
      wsh.RegWrite(regBasePath + "ProxyServer", "", "REG_SZ");
      // 禁用代理地址
      wsh.RegWrite(regBasePath + "ProxyOverride", "", "REG_SZ");

      showErrMsg("关闭代理成功")
    }

    // 开启防火墙
    function openWall() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh advfirewall set allprofiles state on ", "", "runas", SHOW_FLAG_0);
      showMsg("开启防火墙成功");
    }

    // 关闭防火墙
    function closeWall() {
      getConf()
      shell.ShellExecute("cmd.exe", "/c netsh advfirewall set allprofiles state off ", "", "runas", SHOW_FLAG_0);
      showErrMsg("关闭防火墙成功");
    }
    // 折叠ibox
    $('.collapse-link').click(function () {
        var ibox = $(this).closest('div.ibox');
        var button = $(this).find('i');
        var content = ibox.find('div.ibox-content');
        content.slideToggle(200);
        button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
        ibox.toggleClass('').toggleClass('border-bottom');
        setTimeout(function () {
            ibox.resize();
            ibox.find('[id^=map-]').resize();
        }, 50);
    });

  </script>

</html>